home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / RevRdist Folder / RevRdist / RevRdist src / RevRdist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-26  |  5.6 KB  |  250 lines  |  [TEXT/KAHL]

  1. /*
  2.  * RevRdist.c - the main routines for RevRdist
  3.  *
  4.  * RevRdist is intended to be similar in utility to the BSD Unix program
  5.  * "rdist".
  6.  * That is, it uses a file of distribution rules ("distfile") to keep
  7.  * the files and folders on client volumes synchronized with those on a
  8.  * server volume.
  9.  * That is about the end of the similarity.
  10.  * RevRdist runs on the client systems, which are assumed to be the
  11.  * student/worker Mac workstations in an AppleShare network.
  12.  * The server volume is assumed to reside on an AppleShare server.
  13.  * RevRdist itself should be in the System Folder of each client, as should
  14.  * its settings file "RevRdist prefs".
  15.  * The prefs file gives the location of the control file, which can be on the
  16.  * client or server.
  17.  * RevRdist normally runs only at reboot time.  It contains an INIT which
  18.  * checks the prefs file to see if it is time to run the full RevRdist.
  19.  * If so, RevRdist is temporarily made the startup application.
  20.  * RevRdist can also be run at any time just by launching it as an ordinary
  21.  * application.
  22.  */
  23.  
  24. #include "RevRdist.h"
  25. #include "TransSkelProto.h"
  26. #include "TransDisplayProto.h"
  27. #include "dispatch.h"
  28. #include <ShutDown.h>
  29.  
  30. Boolean checkAbort (EventRecord *);
  31. void    doAbout (void);
  32. void    doEditMenu (Integer);
  33. void    doFileMenu (Integer);
  34. void    main (void);
  35.  
  36.  
  37. /*
  38.  *=========================================================================
  39.  * checkAbort (e) - check event for <command>-. and set quit flag if needed
  40.  *=========================================================================
  41.  */
  42.  
  43. static
  44. Boolean
  45. checkAbort (theEvent)
  46.     EventRecord *theEvent;
  47. {
  48.     if ( theEvent->what == keyDown
  49.     &&    (theEvent->message & 0xff) == '.'
  50.     &&  (theEvent->modifiers & cmdKey)
  51.        )
  52.     {
  53.         Quit = true;
  54.         return true;
  55.     }
  56.     return false;
  57. }
  58.  
  59.  
  60.  
  61. /*
  62.  *=========================================================================
  63.  * doAbout () - handle About box (using TextDialog routine from net)
  64.  *=========================================================================
  65.  */
  66.  
  67. static
  68. void
  69. doAbout ()
  70. {
  71.     Handle    theText;
  72.  
  73.     theText = GetResource (TYPE_TEXT, RSRC_ABOUT);
  74.     if (theText)
  75.     {
  76.         HLock (theText);
  77.         TextDialog (WIND_ABOUT + RSRC_BASE, theText, 1, 9, true);
  78.         HUnlock (theText);
  79.         ReleaseResource (theText);
  80.     }
  81. }
  82.  
  83.  
  84.  
  85. /*
  86.  *=========================================================================
  87.  * doEditMenu (item) - handle selection from the Edit menu
  88.  * entry:    item = selected item number
  89.  *=========================================================================
  90.  */
  91. static
  92. void
  93. doEditMenu (item)
  94.     Integer            item;
  95. {
  96.     DialogPtr        w;
  97.  
  98.     w = (DialogPtr) FrontWindow ();
  99.     if (w)
  100.     {
  101.         if (w == (DialogPtr) PrefDialog)
  102.             prefDoEMenu(item);
  103.     }
  104. }
  105.  
  106.  
  107.  
  108. /*
  109.  *=========================================================================
  110.  * doFileMenu (item) - handle selection from the File menu
  111.  * entry:    item = selected item number
  112.  *=========================================================================
  113.  */
  114. void
  115. doFileMenu (item)
  116. Integer    item;
  117. {
  118.     WindowPtr        w;
  119.  
  120.     switch (item)
  121.     {
  122.     case FILE_OPEN:
  123.     case FILE_SAVE:
  124.     case FILE_SAVEAS:
  125.         w = FrontWindow ();
  126.         if (w && w == PrefDialog)
  127.             prefDoFMenu (item);
  128.         break;
  129.     case FILE_QUIT:
  130.         Quit = true;
  131.         if (Pause == S_PAUSED)
  132.             Pause = S_RUNNING;
  133.         Flags &= ~PF_TOUCH;
  134.         break;
  135.     }
  136. }
  137.  
  138.  
  139.  
  140. /*
  141.  *=========================================================================
  142.  * doWindowMenu (item) - handle selection from window menu
  143.  * entry:    item = menu selection number
  144.  *=========================================================================
  145.  */
  146.  
  147. void
  148. doWindowMenu (item)
  149. Integer    item;
  150. {
  151.     WindowPtr w;
  152.  
  153.     switch (item)
  154.     {
  155.     case WIND_STATUS:    w = StatusDialog;    break;
  156.     case WIND_ACTIVITY:    w = ActivityWind;    break;
  157.     case WIND_ERRORS:    w = ErrorWind;        break;
  158.     case WIND_PREF:        w = PrefDialog;
  159.                         Pending = PA_PREF;    break;
  160.     default:            w = nil;
  161.     }
  162.     if (w)
  163.     {
  164.         SelectWindow (w);
  165.         ShowWindow (w);
  166.     }
  167. }
  168.  
  169.  
  170.  
  171.  
  172. /*
  173.  *=========================================================================
  174.  * main () - Set things up and turn control over to SkelMain ()
  175.  *=========================================================================
  176.  */
  177.  
  178.  
  179. static unsigned char    nullstr[1] = { 0 };
  180. void
  181. main ()
  182. {
  183.     Handle        h;
  184.     MenuHandle    m;
  185.     short result;
  186.     Str255        s;
  187.  
  188.     NullStr = nullstr;
  189.     SkelInit (6, nil);                /* initialize */
  190.     /*
  191.      * Set up our menus: Apple, File, Edit (inactive), and Windows
  192.      */
  193.     m = GetMenu (1);                /* Apple */
  194.     if (!m)
  195.         goto abandon;
  196.     GetItem (m, 1, s);                /* About... text */
  197.     SkelApple (s, doAbout);            /* handle desk accessories */
  198.  
  199.     m = GetMenu (2);                /* File */
  200.     if (!m)
  201.         goto abandon;
  202.     if (!SkelMenu (m, (vProcPtr)doFileMenu, nil, false))
  203.         goto abandon;
  204.     DisableItem (m, FILE_OPEN);
  205.     DisableItem (m, FILE_SAVE);
  206.     DisableItem (m, FILE_SAVEAS);
  207.  
  208.     m = GetMenu (3);                /* Edit */
  209.     if (!m)
  210.         goto abandon;
  211.     if (!SkelMenu (m, (vProcPtr)doEditMenu, nil, false))
  212.         goto abandon;
  213.     DisableItem (m, 0);                /* disable it */
  214.  
  215.     m = GetMenu (4);                /* Window */
  216.     if (!m)
  217.         goto abandon;
  218.     if (!SkelMenu (m, (vProcPtr)doWindowMenu, nil, false))
  219.         goto abandon;
  220.     DisableItem (m, 0);                /* disable it for now */
  221.     DrawMenuBar ();
  222.  
  223.     initGlobals ();
  224.     if (!Quit)                        /* if initialized okay */
  225.     {
  226.         if (Flags & PF_LOCKED)
  227.             DisableItem (m, WIND_PREF);    /* if locked, can't do prefs */
  228.         EnableItem (m, 0);            /* Okay to enable Windows now */
  229.         DrawMenuBar ();
  230.  
  231.         SkelEventHook (checkAbort);
  232.         SkelBackground (dispatch);
  233.  
  234.         Pending = PA_PREF;
  235.         if ((Flags & PF_STARTUP)
  236.         ||    File_list[FL_PREF].f_launch
  237.         ||  File_list[FL_DIST].f_launch)
  238.             Pending = PA_GO;
  239.  
  240.         showstat ();
  241.         result = pushCall (idle, nil);
  242.         if (result == R_CONT)
  243.             SkelMain ();
  244.     }
  245. abandon:
  246.     SkelClobber ();                    /* clean up */
  247.     tidyUp ();                        /* more clean up */
  248.     if (Flags & PF_RESTART)            /* reboot if requested */
  249.         ShutDwnStart ();
  250. }